<!-- 首页分发页 -->
<template>
	<view class="container">
		<!-- 空模板，或加个 loading -->
		<view class="loading">加载中...</view>

		<TableBar :current="0" />
	</view>
</template>

<script>
	// import Cache from '@/utils/cache';
	import TableBar from '@/components/base/table-bar/Index.vue'
	import Cache from '@/utils/cache';
	import {
		getBaseUserInfo,
		getUserIdentityStatus
	} from '@/api/base/user-center'; // 注意：新接口无参数
	import {
		IDENTITY
	} from '@/config/cache';
	import {
		mapGetters
	} from 'vuex'

	export default {
		data() {
			return {
				userIdentity: 1, //用户身份， 默认为创作者
			}
		},
		onLoad() {
			// this.redirectToRoleHome();
		},
		components: {
			TableBar
		},
		onShow() {
			// 防止用户从其他页面返回时卡住
			this.redirectToRoleHome();
		},
		computed: {
			...mapGetters(['isLogin'])
		},
		methods: {
			redirectToRoleHome() {

				if (this.isLogin) {
					let _this = this
					getUserIdentityStatus().then(res=>{
						// console.error('登录用户信息', res.data);
						if(res.status === 200 && res.data){
							_this.userIdentity = res.data.identity
						}
						// console.error('登录用户信息', _this.userIdentity);
						if (_this.userIdentity === 2 || _this.userIdentity == '2') {
							//设计师首页
							uni.redirectTo({
								url: '/pages/base/index/designer-index/index'
							});
						} else if(_this.userIdentity === 1 || _this.userIdentity == '1') {
							//创造者首页
							uni.redirectTo({
								url: '/pages/base/index/creator-index/index'
							});
						}else if(_this.userIdentity === 3 || _this.userIdentity == '3'){
							//居间人首页
							uni.redirectTo({
								url: '/pages/base/between-home/index'
							});
						}else{
							//注册页
							uni.redirectTo({
								url: '/pages/sub_base/register/index'
							});
						}
					})
				}else{
					//创造者首页
					uni.redirectTo({
						url: '/pages/base/index/creator-index/index'
					});
				}

			},
		},
	}
</script>

<style scoped>
	.container {
		min-height: 100vh;
		background-color: #F2F8FC;
		overflow: hidden;
		position: relative;
	}

	.loading {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 100vh;
		color: #999;
	}
</style>